import request from "@/utils/request";
import { doUpload } from "@/api/tool/ossTool";

/**
 * 上传json文件
 * @param str 路径名
 * @param data 内容
 * @returns {Promise<AxiosResponse<any>>}
 */
export function uploadJsonFile(str, data) {
  // 创建FormData
  const formData = new FormData();
  formData.append(
    "file",
    new Blob(
      [
        JSON.stringify({
          data: data,
          code: 200,
          msg: "成功",
        }),
      ],
      { type: "application/json" }
    ),
    "data.json"
  );

  return doUpload(formData);
}

/**
 * 获取json文件
 * @param url
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getJsonFile(url) {
  return request({
    url: url,
    method: "get",
  });
}
